import javax.xml.soap.Node;
import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-05-12
 * Time: 19:02
 */
class Person {
    public String id;

    public Person(String id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "Person{" +
                "id='" + id + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return Objects.equals(id, person.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}

public class Test {

    public static void func1(int[] arr) {
        Set<Integer> set = new HashSet<>();
        //Set<Integer> set = new TreeSet<>();//TreeMap和TreeSet
        for (int i = 0; i < arr.length; i++) {
            set.add(arr[i]);
        }
        System.out.println(set);
    }
    public static void main6(String[] args) {
        int[] arr = {1, 6, 8, 6, 8, 4};
        func1(arr);
    }
    public static void main3(String[] args) {
        Person person1 = new Person("1234");
        Person person2 = new Person("1234");
//        System.out.println(person1.hashCode());
//        System.out.println(person2.hashCode());
        HashBuck<Person, String> hashBuck = new HashBuck<>();
        hashBuck.put(person1, "amy");

        String name = hashBuck.get(person2);
        System.out.println(name);
    }
    public static void main4(String[] args) {
        HashBucket hashBucket = new HashBucket();
        hashBucket.put(1, 11);
        hashBucket.put(2, 12);
        hashBucket.put(12, 122);
        hashBucket.put(3, 13);
        hashBucket.put(4, 14);
        hashBucket.put(14, 114);
        hashBucket.put(5, 15);
        hashBucket.put(6, 16);

        hashBucket.getValue(1);

    }
    public static void main2(String[] args) {
        Set<String> strings = new TreeSet<>();
        strings.add("asc");
        strings.add("isn");
        strings.add("ojs");
        strings.add("ojs");
        //set中的元素是不能重复的， 这里TreeSet底层是TreeMap，每次存储元素到map的key上
        //strings.clear();
        Iterator<String> iterator = strings.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    }
    public static void main1(String[] args) {
        Map<String, Integer> map = new TreeMap<>();
        map.put("hello", 3);
        map.put("abds", 2);
        map.put("abde", 3);
        map.put("abdf", 4);
        map.put("hello", 4);//相同的key，更新value
//        Set<String> stringSet = map.keySet();
//        System.out.println(map.getOrDefault("abde",11));
//        map.remove("abde");
//        System.out.println(map.getOrDefault("abde",11));
        Set<Map.Entry<String, Integer>> entrySet = map.entrySet();

        for (Map.Entry<String, Integer> entry:
             entrySet) {
            System.out.println("key : " + entry.getKey() + " val : " + entry.getValue());
        }
        System.out.println();
    }
}
